/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client.subsistema3;

import beans.Constants;
import beans.Estudiant;
import beans.ResponsableEvents;
import common.EOlympicsException;
import common.RemoteInterface;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.rmi.RemoteException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.JOptionPane;


/**
 *
 * @author Gelio
 */
public class PantallaResumExecutiu extends javax.swing.JFrame {
    
        
    private RemoteInterface remoto;
    private ResponsableEvents responsable;
    private java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("i18n/subsistema3/messagesSubsistema3");
    private Vector numInscrits;
    private List<String> universitats;
    
        

    /**
     * Creates new form PantallaResumExecutiu
     */
    public PantallaResumExecutiu(RemoteInterface pRemoto, ResponsableEvents pResponsable){
        
        initComponents();
        
        remoto = pRemoto;
        responsable = pResponsable;
        String estatProvaInscripcio = new String();
        String estatProvaFinalitzada = new String();
        String estatProvaPrevia = new String();
        String estatProvaFinal = new String();
        Float mitjaInscrits;
        
        
        
        // center the jframe on screen
        this.setLocationRelativeTo(null);
        
        
        System.out.println("PantallaResumExecutiu");
        
        try{
            
            //Posem tots els textos seguint l'estructura i18n
            setTextosPantallaResum();
                        
            //obtenim els diferents tipus d'estat de les proves
            estatProvaInscripcio = getConstantInscripcio();
            estatProvaFinalitzada = getConstantFinalitzada();
            estatProvaPrevia = getConstantPrevia();
            estatProvaFinal = getConstantFinal();
            
            //obtenim el llistat d'universitats
            universitats = getUniversitats();
            //mitjaInscrits = getMitjaInscrits();
            
            
            //valors de les estadistiques
            numProves.setText(remoto.sub3getNumProves());          
            numProvesCurs.setText(remoto.sub3getNumProvesCurs(estatProvaPrevia, estatProvaFinal));
            numProvesFinalitzades.setText(remoto.sub3getNumProvesFinalitzades(estatProvaFinalitzada));
            numEstudiantsInscrits.setText(remoto.sub3getNumEstudiantsInscrits());
            numMedalles.setText(String.valueOf(Integer.parseInt(numProvesFinalitzades.getText())*3));
            numUniversitats.setText(String.valueOf(universitats.size()));
            numMitjaInscrits.setText(String.valueOf(Float.parseFloat(numEstudiantsInscrits.getText()) / Float.parseFloat(numProves.getText())));
            notaMitja.setText(remoto.sub3getPuntuacioMitjana());
            
            
            
          
       
       
        }catch (RemoteException e){
            
            System.out.print("RemoteException Exception: " +e);
            
        }catch (EOlympicsException e) {
            
            System.out.print("EOlympicsException Exception: +e");
        
        }catch (Exception e){
            
            System.out.print("Exception Exception: " +e);
            
        }

    }
    
    public List<String> getUniversitats(){
        
        universitats = new ArrayList<String>();
        Properties prop = new Properties();
        final String propertiesFile = new File("").getAbsolutePath() + "/properties/generalVars.properties";
        try {
            prop.load(new FileInputStream(propertiesFile));
            
            String universitatsStr = prop.getProperty("universitats");
        
            String[] unis = universitatsStr.split(",");
            for(int i = 0; i<unis.length; i++){
                universitats.add(unis[i]);
            }
        } catch (IOException ex) {
                Logger.getLogger(PantallaResumExecutiu.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return universitats;
        
    }
    
    
    public void setTextosPantallaResum(){
        
        titolResumText.setText(bundle.getString("sub3.text.TitolResumExecutiu"));
        numProvesText.setText(bundle.getString("sub3.text.numProvesTotals"));
        numProvesCursText.setText(bundle.getString("sub3.text.numProvesCurs"));
        numProvesFinalitzadesText.setText(bundle.getString("sub3.text.numProvesFinalitzades"));
        numEstudiantsInscritsText.setText(bundle.getString("sub3.text.numEstudiantsInscrits"));
        numMedallesText.setText(bundle.getString("sub3.text.numMedallesRepartir"));
        numUniversitatsText.setText(bundle.getString("sub3.text.numUniversitats"));
        numMitjaInscritsText.setText(bundle.getString("sub3.text.numMitjaInscrits"));
        notaMitjaText.setText(bundle.getString("sub3.text.notaMitjaProves"));
        
        
    }
    
    /*
     * Funcio que torna la constant per definir les proves en estat d'inscripcio
     */
    public String getConstantInscripcio(){

        return new String(Constants.PROVA_EN_PROCES_INSCRIPCIO);
    }
    
    /*
    * Funcio que torna la constant per definir les proves finalitzades
    */
    public String getConstantFinalitzada(){

        return new String(Constants.PROVA_EN_CLASSIFICACIO_FINAL);
    }
    
    /*
     * Funcio que torna la constant per definir les proves en estat previ
     */
    public String getConstantPrevia(){

        return new String(Constants.PROVA_EN_COMPETICIO_PREVIA);
    }    
    
    /*
     * Funcio que torna la constant per definir les proves en estat previ
     */
    public String getConstantFinal(){

        return new String(Constants.PROVA_EN_COMPETICIO_FINAL);
    }
    
    /**
     * Tanca la finestra
     * @param evt event que executa l'acció
     */
  /*  private void tancarFinestra(java.awt.event.ActionEvent evt) {                                

            int i = JOptionPane.showConfirmDialog(this, bundle.getString("client.administracio.confirmar_tancar_administracio"), 
                bundle.getString("client.titol_alerta_client"), JOptionPane.WARNING_MESSAGE);
        
            this.dispose();
    }*/    
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        numProvesText = new javax.swing.JLabel();
        numProves = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        titolResumText = new javax.swing.JLabel();
        numEstudiantsInscrits = new javax.swing.JLabel();
        numEstudiantsInscritsText = new javax.swing.JLabel();
        numProvesFinalitzades = new javax.swing.JLabel();
        numProvesFinalitzadesText = new javax.swing.JLabel();
        numMedallesText = new javax.swing.JLabel();
        numMedalles = new javax.swing.JLabel();
        numUniversitats = new javax.swing.JLabel();
        numUniversitatsText = new javax.swing.JLabel();
        numProvesCurs = new javax.swing.JLabel();
        numProvesCursText = new javax.swing.JLabel();
        numMitjaInscrits = new javax.swing.JLabel();
        numMitjaInscritsText = new javax.swing.JLabel();
        notaMitja = new javax.swing.JLabel();
        notaMitjaText = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        numProvesText.setText("jLabel1");

        numProves.setText("jLabel1");

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        titolResumText.setText("jLabel1");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titolResumText)
                .addContainerGap(483, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titolResumText)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        numEstudiantsInscrits.setText("jLabel1");

        numEstudiantsInscritsText.setText("jLabel1");

        numProvesFinalitzades.setText("jLabel1");

        numProvesFinalitzadesText.setText("jLabel1");

        numMedallesText.setText("jLabel1");

        numMedalles.setText("jLabel2");

        numUniversitats.setText("jLabel1");

        numUniversitatsText.setText("jLabel1");

        numProvesCurs.setText("jLabel1");

        numProvesCursText.setText("jLabel1");

        numMitjaInscrits.setText("jLabel1");

        numMitjaInscritsText.setText("jLabel1");

        notaMitja.setText("jLabel2");

        notaMitjaText.setText("jLabel2");

        jMenu1.setText("File");

        jMenuItem1.setText("Tancar");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                System.out.println("Tancar finestra");

                tancarFinestra(evt);
            }
        });

        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(numUniversitatsText)
                            .addComponent(numMedallesText)
                            .addComponent(numEstudiantsInscritsText)
                            .addComponent(numProvesFinalitzadesText)
                            .addComponent(numProvesCursText)
                            .addComponent(numProvesText)
                            .addComponent(numMitjaInscritsText)
                            .addComponent(notaMitjaText))
                        .addGap(46, 46, 46)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(numUniversitats, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(numMedalles, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(numEstudiantsInscrits, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(numProvesFinalitzades, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(numProvesCurs, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(numProves, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(numMitjaInscrits, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(notaMitja, javax.swing.GroupLayout.Alignment.LEADING))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(numProvesText)
                    .addComponent(numProves))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(numProvesCursText)
                    .addComponent(numProvesCurs))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(numProvesFinalitzadesText)
                    .addComponent(numProvesFinalitzades))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(numEstudiantsInscrits)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(numMedalles)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(numUniversitats))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(numEstudiantsInscritsText)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(numMedallesText)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(numUniversitatsText)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(numMitjaInscrits)
                    .addComponent(numMitjaInscritsText))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(notaMitja)
                    .addComponent(notaMitjaText))
                .addContainerGap(174, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tancarFinestra(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tancarFinestra
        System.out.println("tancarFinestra");
        int i = JOptionPane.showConfirmDialog(this, "Vol tancar la finestra?",
            "Confirmacio Tancar", JOptionPane.YES_NO_OPTION);

            if(i == 0)
                this.dispose();
        
    }//GEN-LAST:event_tancarFinestra

  
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel notaMitja;
    private javax.swing.JLabel notaMitjaText;
    private javax.swing.JLabel numEstudiantsInscrits;
    private javax.swing.JLabel numEstudiantsInscritsText;
    private javax.swing.JLabel numMedalles;
    private javax.swing.JLabel numMedallesText;
    private javax.swing.JLabel numMitjaInscrits;
    private javax.swing.JLabel numMitjaInscritsText;
    private javax.swing.JLabel numProves;
    private javax.swing.JLabel numProvesCurs;
    private javax.swing.JLabel numProvesCursText;
    private javax.swing.JLabel numProvesFinalitzades;
    private javax.swing.JLabel numProvesFinalitzadesText;
    private javax.swing.JLabel numProvesText;
    private javax.swing.JLabel numUniversitats;
    private javax.swing.JLabel numUniversitatsText;
    private javax.swing.JLabel titolResumText;
    // End of variables declaration//GEN-END:variables
}
